package com.xzl.org.learning_situation_analysis.util;

/**
 * @author 吴泽胜
 * @FileName MessageUtils
 * @date 2021-06-22 3:42 下午
 * @Software: IntelliJ IDEA
 */


import com.xzl.org.learning_situation_analysis.enums.HttpStatus;
import com.xzl.org.learning_situation_analysis.response.RestResponse;

/**
 * MessageUtils快捷构建类
 */
public final class MessageUtils {

    /**
     * 成功时-返回data
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> success(T data){
        return new RestResponse<T>(HttpStatus.ISOK.getCode(), null, data);
    }

    /**
     * 成功时-返回data
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> success(T data,Integer count){
        return new RestResponse<T>(HttpStatus.ISOK.getCode(), null, data,count);
    }

    /**
     * 成功-不返回data
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> success(String msg){
        return new RestResponse<T>(HttpStatus.ISOK.getCode(), msg);
    }

    /**
     * 成功-返回data+msg
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> success(String msg, T data){
        return new RestResponse<T>(HttpStatus.ISOK.getCode(), msg, data);
    }

    /**
     * 失败
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> fail(String msg){
        return new RestResponse<T>(HttpStatus.NoOK.getCode(), msg,null);
    }

    /**
     * 失败-code
     * @param <T>
     * @return
     */
    public static <T> RestResponse<T> fail(int code, String msg){
        return new RestResponse<T>(code, msg,null);
    }
}



